package com.fita.admin.service.data.impl;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.fita.admin.dao.CountryCouponDao;
import com.fita.admin.service.DataServiceImpl;
import com.fita.admin.service.data.DiscountService;
import com.fita.entity.data.Country;
import com.fita.entity.data.CountryCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 
 * @author cuteHU
 *
 */
@Service("discountService")
public class DiscountServiceImpl extends DataServiceImpl<CountryCoupon> implements DiscountService {

    @Dao
    private CountryCouponDao countrycouponDao;

    @Autowired
    private GenericDaoSupport genericDaoSupport;

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.fita.admin.service.data.DiscountService#createCoupon(com.fita.entity.data
     * .Coupon, com.fita.entity.data.Country)
     */
    public void createCoupon(CountryCoupon coupon, Country country) {
        genericDaoSupport.save(coupon.initliaze(country));
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.fita.admin.service.data.DiscountService#updateCoupon(com.fita.entity.data
     * .Coupon, com.fita.entity.data.Country)
     */
    public void updateCoupon(CountryCoupon coupon, Country country) {
        genericDaoSupport.update(coupon.addCountry(country));
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.fita.admin.service.data.DiscountService#activate(com.fita.entity.data.
     * Coupon)
     */
    public void activate(CountryCoupon coupon) {
        genericDaoSupport.update(coupon.activate());
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.fita.admin.service.data.DiscountService#freeze(com.fita.entity.data.
     * Coupon)
     */
    public void freeze(CountryCoupon coupon) {
        genericDaoSupport.update(coupon.freeze());
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.fita.admin.service.data.DiscountService#deleteCoupon(java.lang.Long)
     */
    public void deleteCoupon(Long couponId) {
        countrycouponDao.changeStatus(couponId);
    }

}
